/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gblend.exactquery;

import gblend.adjlistgraph.ALGraph;
import gblend.adjlistgraph.FsgIdEntry;
import gblend.frequentindex.Vertex;
import gblend.largegraph.structure.SInterSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;

/*
* Copyright 2010, Center for Advanced Information Systems,Nanyang Technological University
*
* File name: SNode.java
*
* Abstract: The SPIG node structure
*
* Current Version:      0.1
* Auther:               Jin Changjiu
* Modified Date:        Feb.22,2010
*
*/

/**
 *
 * @author cjjin
 */
public class SNode extends ALGraph{
    
   private Vertex[] vertexs ;
   private int[][] adjMat;
   private int pos = -1;
  
   private int wholeFreq = -1;
   private int wholeDif = -1;
   private int clusterId = -1;

   private HashSet<Integer>  difIdlist = new HashSet<Integer>();
   private HashSet<Integer>  freqIdlist = new HashSet<Integer>();
   private Vector<Integer> qIdSet = new Vector<Integer>(); 
   private Vector<Integer> elabelset = new Vector<Integer>();
   //FOR LARGE GRAPH
//   private Vector<HashSet<FsgIdEntry>> candparentlist=new Vector<HashSet<FsgIdEntry>>();
   //map from parent graphs Id to their cluster's id
   private HashMap<Integer,Integer> clustermap=new HashMap<Integer,Integer>();
   private SInterSet intersectlist=new SInterSet();

  public SNode(int size)
  {
      super(size);
       vertexs = new Vertex[size];
       pos = -1;

       adjMat = new int[size][size];
       for(int i = 0; i < size; i++)
       {
           for(int j = 0; j< size; j++)
           {
               adjMat[i][j]=0;
           }
       }
   }

//add formulation sequence as the label of the edge
    public void addEdge(int from, int to, int label)
    {
        adjMat[from][to] = label;
        adjMat[to][from] = label;
    }
 
    @Override
    public int getEdge(int from, int to)
    {
        return adjMat[from][to];
    }
 
     public void setDifIds(int gid)
     {
        difIdlist.add(gid);
     }

     public HashSet<Integer> getDifIds()
     {
        return difIdlist;
     }

     public void setFreIds(int gid)
     {
        freqIdlist.add(gid);
     }

     public HashSet<Integer> getFreIds()
     {
        return freqIdlist;
     }

     public void setItsFreqId(int id)
     {
        wholeFreq = id;
     }

     public int getItsFreqId()
     {
        return wholeFreq;
     }

     public void setItsDifId(int id)
     {
        wholeDif = id;
     }


     public int getItsDifId()
     {
        return wholeDif;
     }

     //if exnode is a frequent, which cluster does it belong to
     public void setClusterId(int id)
     {
        clusterId = id;
     }

     public void setClusterList(int parentgid,int clusterid){
         clustermap.put(parentgid, clusterid);
     }

     public int getClusterIdFromList(int parentgid){
         return clustermap.get(parentgid);
     }

     public int getClusterId()
     {
        return clusterId;
     }

     //for exnode generatioin
     public void setIdinQuery(int id)
     {
        qIdSet.addElement(id);
     }

     public void setIdSetinQuery(Vector<Integer> idset)
     {
        qIdSet.addAll(idset);
     }
     
     public Vector<Integer> getIDsetinQuery()
     {
        return qIdSet;
     }

    public void setEdgelabeSet(int label)
    {
        elabelset.addElement(label);
    }
    
    public Vector<Integer> getEdgelabelSet()
    {
        return elabelset;
    }

    public void addCandParentEntrySet(HashSet<FsgIdEntry> newset){
        /*if(intersectlist.getSet().size()==0){
            Iterator<FsgIdEntry> newsi = newset.iterator();
            while(newsi.hasNext()){
                FsgIdEntry newsie = newsi.next();
                intersectlist.add(newsie);
            }
        }else{*/
         //  intersectlist= IntersectSet.intersect(intersectlist, newset);
            intersectlist.addSecondSet(newset);
        //}
    }

    public void resetCandParentList(){
        intersectlist = new SInterSet();
    }

    public SInterSet getCandParentList(){
        return intersectlist;
    }

    public boolean isCandParentListEmpty(){
        return intersectlist.isEmpty();
    }

    public void print(){
        System.out.print("wholeFreq="+wholeFreq+",wholeDif="+wholeDif+",clusterId="+clusterId+",freqIdlist=(");
        Iterator<Integer> fili = freqIdlist.iterator();
        while(fili.hasNext()){
            System.out.print(fili.next()+",");
        }
        System.out.print("),difIdlist=(");
        fili=difIdlist.iterator();
        while(fili.hasNext()){
            System.out.print(fili.next()+",");
        }
        System.out.print("),qIdSet=(");
        fili=qIdSet.iterator();
         while(fili.hasNext()){
            System.out.print(fili.next()+",");
        }
        System.out.print("),elabelset=(");
        fili=elabelset.iterator();
         while(fili.hasNext()){
            System.out.print(fili.next()+",");
        }
        System.out.println("),idlist size="+intersectlist.getOrderedSet().size()+":");
        intersectlist.print();
        //System.out.println();
    }

    void finaliseCandParentList() throws Exception{
        intersectlist.finalCombine();
    }

}
